package com.blx.utils;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.w3c.dom.NodeList;

public class XMLParseHelper {

	public static Map<String, String> ReadXML(String path){
		//拿到src文件夹里的xml配置文件
		  String url = XMLParseHelper.class.getClassLoader().getResource(path).getPath();
		  Map<String, String> map=new HashMap<String, String>();
		  try {
		   //创建读取配置文件的对象
		   SAXReader reader = new SAXReader();
		   //开始读取配置文件
		   Document doc = reader.read(new File(url));
		   //拿到根节点
		   Element root = doc.getRootElement();
		   List<Element> elems = root.elements();
		   for(Element elem : elems) {
			    String id = elem.attributeValue("id");
			    String value = elem.getText();
			    map.put(id, value);
			}
		   }catch (Exception e) {
		   e.printStackTrace();
		  }
		  return map;
	}
//	public static void main(String[] args) {
//		Map<String,Object> map = XMLParseHelper.ReadXML("spring/smstemplate.xml");
//		System.out.println();
//	}
}
